package a16_ArrayCaculateValue;

/**
 * @Author quan
 * @Description 首尾交换数组元素{1,2,3,4,5}——>{5,4,3,2,1}
 * @Date 2023/2/1 17:57
 */
public class changeIndexArray {
    public static void main(String[] args) {
        //交换数组:for循环里定义两个变量i和j
        int[] arr = {1,2,3,4,5};
//        for (int i =0,j=arr.length-1;i<j;i++,j--){
//            int temp = arr[i];
//            arr[i]=arr[j];
//            arr[j]= temp;
//        }
        for (int i = 0; i < arr.length/2; i++) {
            int temp;
            temp = arr[i];
            arr[i] = arr[arr.length-i-1];
            arr[arr.length-i-1] = temp;
        }
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
